package core.behaviors;

import util.PlayerCatalog;
import core.Actor;
import core.CoreTypes;
import core.conditions.Condition;
/**
 * Update a trait when stepped through
 * 
 * Given a player, trait, and value update the trait on each step by the given value.
 * 
 * @author Alexander Schearer <aas11@duke.edu>
 */
public class UpdateTrait extends Behavior {
	
	private String myPlayer;
	
	private String myTrait;
	
	private int myValue;

	public UpdateTrait(String player, String trait, int value) {
		super(CoreTypes.UPDATETRAIT);
		init(player, trait, value);
	}
	
	public UpdateTrait(String player, String trait, int value, Condition... c) {
		super(CoreTypes.UPDATETRAIT, c);
		init(player, trait, value);
	}
	
	private void init(String player, String trait, int value)
	{
		myPlayer = player;
		myTrait = trait;
		myValue = value;
	}
	
	public void step(Actor... actors)
	{
		PlayerCatalog.getSingleton().lookup(myPlayer).update(myTrait, myValue); // TODO handle the possible null pointer exception
		super.step();
	}

}
